<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_FusionCharts
 * @subpackage Theme
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: KRIBar.php 7 2009-11-14 22:42:08Z nkeyes $
 */

/**
 * 
 * @author Nathan Keyes
 *
 */
class Bushido_FusionCharts_Theme_KRIBar extends Bushido_FusionCharts_Theme_SingleSeries
{

	
	/**
	 * 
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
		$this->name = 'KRIBar';
		$this->chartType = Bushido_FusionCharts::COLUMN;
	}
	
	
	/**
	 * (non-PHPdoc)
	 * @see library/Bushido/FusionCharts/Theme/Bushido_FusionCharts_Theme_SingleSeries#getDataNode()
	 */
	public function getDataNode($label, $value)
	{
		$colorHex = $this->_getColorHex($value);
		$toolText = $label . ': ' . $this->_getStatusLabel($value);
		
		if($value >= 0)
		{
			$alpha = 100;
		}
		else
		{
			$alpha = 50;
			$value = 100;
		}
		$setNode =  "<set label='" . htmlentities($label) . "' value='$value' color='$colorHex' toolText='$toolText' alpha='$alpha'/>";
		return $setNode;
	}
	
	
	/**
	 * 
	 * @param $value
	 * @return string
	 */
	protected function _getColorHex($value)
	{
		if($value >= 0)
		{
			$redDecimal = $value >= 50 ? 255 : floor($value * 5.1);
			$greenDecimal = $value <= 50 ? 255 : floor((100 -$value) * 5.1);
			
			
			$redHex = dechex($redDecimal);
			$greenHex = dechex($greenDecimal);
			
			$redHex = $redDecimal < 16 ? '0' . $redHex : $redHex;
			$greenHex = $greenDecimal < 16 ? '0' . $greenHex : $greenHex;
			$colorHex = $redHex . $greenHex . '00';
		}
		else
		{
			$colorHex = 'AAAAAA';
		}
		
		return $colorHex;
	}
	
	
	/**
	 * 
	 * @param $value
	 * @return string
	 */
	protected function _getStatusLabel($value)
	{
		if($value > 66.667)
		{
			return 'High';
		}
		elseif($value > 33.333)
		{
			return 'Medium';
		}
		elseif($value >= 0)
		{
			return 'Low';
		}
		else
		{
			return 'NO DATA';
		}
	}
}
